package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.db.conn;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



public class reimburse_List extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public reimburse_List() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	//根据条件返回退款申请信息
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;");
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setHeader("Access-Control-Allow-Methods", "GET,POST");
		PrintWriter out = response.getWriter();
		JSONArray jsonarray = new JSONArray();
		JSONObject jsonobj = new JSONObject();


		conn cn = new conn();
	
	    String f=request.getParameter("f");

		ResultSet rs=null;

		if(f.equals("1"))
		{
			String uid = request.getParameter("uid");
			rs=cn.query("select * from  reimburse where no in(select no from orders where uid="+uid+") order by id desc ");
		}
		else if(f.equals("2"))
		{
			rs=cn.query("select * from  reimburse  ");
		}

		while (true)
		{
			try {
				if (!rs.next()) break;
             jsonobj.put("id", rs.getString("id"));
             jsonobj.put("no", rs.getString("no"));
             jsonobj.put("ques", rs.getString("ques"));
             jsonobj.put("rtime", rs.getString("rtime"));
             jsonobj.put("rflag", rs.getString("rflag"));
             jsonobj.put("rsults", rs.getString("rsults"));
		
				jsonarray.add(jsonobj);

			} catch (SQLException e) {
				e.printStackTrace();
			}

		}

		out.println(jsonarray);	
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

